<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>ElasticSearch 入门介绍 | 知识是最有价值的东西</title>
  <meta name="description" content="ElasticSearch 简介 ES是一个基于Lucene的分布式全文搜索服务器，和SQL Server的全文索引（Fulltext Index）有点类似，都是基于分词和分段的全文搜索引擎，具有分词，同义词，词干查询的功能，但是ES天生具有分布式和实时的属性。 ElasticSearch官网：http:&#x2F;&#x2F;www.elasticsearch.org  ElasticSearch 与 MySql">
<meta property="og:type" content="article">
<meta property="og:title" content="ElasticSearch 入门介绍">
<meta property="og:url" content="http:&#x2F;&#x2F;jirenyou.gitee.io&#x2F;blog&#x2F;2020&#x2F;01&#x2F;02&#x2F;elasticsearch&#x2F;es-desc&#x2F;index.html">
<meta property="og:site_name" content="知识是最有价值的东西">
<meta property="og:description" content="ElasticSearch 简介 ES是一个基于Lucene的分布式全文搜索服务器，和SQL Server的全文索引（Fulltext Index）有点类似，都是基于分词和分段的全文搜索引擎，具有分词，同义词，词干查询的功能，但是ES天生具有分布式和实时的属性。 ElasticSearch官网：http:&#x2F;&#x2F;www.elasticsearch.org  ElasticSearch 与 MySql">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-01-02T12:24:15.000Z">
<meta property="article:modified_time" content="2020-01-02T12:24:15.000Z">
<meta property="article:author" content="Jirry">
<meta property="article:tag" content="elasticsearch">
<meta name="twitter:card" content="summary">
  <!-- Canonical links -->
  <link rel="canonical" href="http://jirenyou.gitee.io/blog/2020/01/02/elasticsearch/es-desc/index.html">
  
    <link rel="alternate" href="/atom.xml" title="知识是最有价值的东西" type="application/atom+xml">
  
  
    <link rel="icon" href="/blog/favicon.ico" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 4.1.0"></head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://jirenyou.gitee.io/blog" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">Jirry</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Back end development Architecture</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Shenzhen, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="/blog/repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="/blog/links">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/docker/">docker</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/elasticsearch/">elasticsearch</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/java/">java</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/php/">php</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/">语法</a><span class="category-list-count">1</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/markdown-%E8%AF%AD%E6%B3%95/">markdown 语法</a><span class="category-list-count">1</span></li></ul></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/aop/" rel="tag">aop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/bloom-filter/" rel="tag">bloom-filter</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/busybox/" rel="tag">busybox</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/docker/" rel="tag">docker</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/elasticsearch/" rel="tag">elasticsearch</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/es/" rel="tag">es</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/filter/" rel="tag">filter</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/git/" rel="tag">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/hashMap/" rel="tag">hashMap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/idea/" rel="tag">idea</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/interceptor/" rel="tag">interceptor</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/iterator/" rel="tag">iterator</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/java/" rel="tag">java</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/localDateTime/" rel="tag">localDateTime</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/map/" rel="tag">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/markdown/" rel="tag">markdown</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/maven/" rel="tag">maven</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis/" rel="tag">redis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" rel="tag">redis lua脚本</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/volumes/" rel="tag">volumes</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/aop/" style="font-size: 13px;">aop</a> <a href="/blog/tags/bloom-filter/" style="font-size: 13px;">bloom-filter</a> <a href="/blog/tags/busybox/" style="font-size: 13px;">busybox</a> <a href="/blog/tags/docker/" style="font-size: 14px;">docker</a> <a href="/blog/tags/elasticsearch/" style="font-size: 13.67px;">elasticsearch</a> <a href="/blog/tags/es/" style="font-size: 13px;">es</a> <a href="/blog/tags/filter/" style="font-size: 13.33px;">filter</a> <a href="/blog/tags/git/" style="font-size: 13.33px;">git</a> <a href="/blog/tags/hashMap/" style="font-size: 13px;">hashMap</a> <a href="/blog/tags/idea/" style="font-size: 13px;">idea</a> <a href="/blog/tags/interceptor/" style="font-size: 13px;">interceptor</a> <a href="/blog/tags/iterator/" style="font-size: 13px;">iterator</a> <a href="/blog/tags/java/" style="font-size: 13.67px;">java</a> <a href="/blog/tags/localDateTime/" style="font-size: 13px;">localDateTime</a> <a href="/blog/tags/map/" style="font-size: 13px;">map</a> <a href="/blog/tags/markdown/" style="font-size: 13px;">markdown</a> <a href="/blog/tags/maven/" style="font-size: 13.67px;">maven</a> <a href="/blog/tags/redis/" style="font-size: 13px;">redis</a> <a href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" style="font-size: 13px;">redis lua脚本</a> <a href="/blog/tags/volumes/" style="font-size: 13px;">volumes</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/01/">一月 2020</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/12/">十二月 2019</a><span class="archive-list-count">11</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/14/java/maven/mvn-private-repo/" class="title">Maven私服（Nexus）搭建</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-14T13:37:39.000Z" itemprop="datePublished">2020-01-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-idea-start-slow/" class="title">解决Idea启动Spring Boot很慢的问题</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter-in-aop/" class="title">AOP（面向切面编程）、Filter（过虑器）、Interceptor（拦截器）</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-req-resp/" class="title">HttpServletRequest 与 HttpServletResponse 的实现类</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter/" class="title">Spring Boot 过滤器 Filter</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#ElasticSearch-简介"><span class="toc-number">1.</span> <span class="toc-text">ElasticSearch 简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ElasticSearch-与-MySql-对比"><span class="toc-number">2.</span> <span class="toc-text">ElasticSearch 与 MySql 对比</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#RESTful-API-请求"><span class="toc-number">3.</span> <span class="toc-text">RESTful API 请求</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#数据类型"><span class="toc-number">4.</span> <span class="toc-text">数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#字符串类型"><span class="toc-number">4.1.</span> <span class="toc-text">字符串类型</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#text-文本类型"><span class="toc-number">4.1.1.</span> <span class="toc-text">text 文本类型</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#keyword-关键字类型"><span class="toc-number">4.1.2.</span> <span class="toc-text">keyword 关键字类型</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#数字类型"><span class="toc-number">4.2.</span> <span class="toc-text">数字类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#date-日期类型"><span class="toc-number">4.3.</span> <span class="toc-text">date  日期类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#boolean-布尔类型"><span class="toc-number">4.4.</span> <span class="toc-text">boolean 布尔类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#binary-二进制类型"><span class="toc-number">4.5.</span> <span class="toc-text">binary 二进制类型</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#range-范围类型"><span class="toc-number">4.6.</span> <span class="toc-text">range 范围类型</span></a></li></ol></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-elasticsearch/es-desc" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      ElasticSearch 入门介绍
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2020/01/02/elasticsearch/es-desc/" class="article-date">
	  <time datetime="2020-01-02T12:24:15.000Z" itemprop="datePublished">2020-01-02</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/elasticsearch/">elasticsearch</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/elasticsearch/" rel="tag">elasticsearch</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2020/01/02/elasticsearch/es-desc/#comments" class="article-comment-link">评论</a></span>
        
	
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h2 id="ElasticSearch-简介"><a href="#ElasticSearch-简介" class="headerlink" title="ElasticSearch 简介"></a>ElasticSearch 简介</h2><blockquote>
<p>ES是一个基于Lucene的分布式全文搜索服务器，和SQL Server的全文索引（Fulltext Index）有点类似，都是基于分词和分段的全文搜索引擎，具有分词，同义词，词干查询的功能，但是ES天生具有分布式和实时的属性。</p>
<p>ElasticSearch官网：<a href="http://www.elasticsearch.org/" target="_blank" rel="noopener">http://www.elasticsearch.org</a></p>
</blockquote>
<h2 id="ElasticSearch-与-MySql-对比"><a href="#ElasticSearch-与-MySql-对比" class="headerlink" title="ElasticSearch 与 MySql 对比"></a>ElasticSearch 与 MySql 对比</h2><table>
<thead>
<tr>
<th>定义(MySql/ElasticSearch)</th>
<th>MySql</th>
<th>ElasticSearch</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>数据库/索引</td>
<td>Database</td>
<td>Index</td>
<td>相当于数据库，用于定义文档类型的存储；在同一个索引中，同一个字段只能定义一个数据类型</td>
</tr>
<tr>
<td>表/文档类型</td>
<td>Table</td>
<td>Type</td>
<td>相当于关系表，用于描述文档中的各个字段的定义；不同的文档类型，能够存储不同的字段，服务于不同的查询请求</td>
</tr>
<tr>
<td>行/文档</td>
<td>Row</td>
<td>Document</td>
<td>相当于关系表的数据行，存储数据的载体，包含一个或多个存有数据的字段</td>
</tr>
</tbody></table>
<h2 id="RESTful-API-请求"><a href="#RESTful-API-请求" class="headerlink" title="RESTful API 请求"></a>RESTful API 请求</h2><table>
<thead>
<tr>
<th>请求方式</th>
<th>用途</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>GET</td>
<td>获取服务器中的对象</td>
<td>相当于 SQL 的 Select 命令</td>
</tr>
<tr>
<td>POST</td>
<td>在服务器上更新对象</td>
<td>相当于 SQL 的 Update 命令</td>
</tr>
<tr>
<td>PUT</td>
<td>在服务器上创建对象</td>
<td>相当于 SQL 的 Create 命令</td>
</tr>
<tr>
<td>DELETE</td>
<td>删除服务器中的对象</td>
<td>相当于 SQL 的 Delete 命令</td>
</tr>
<tr>
<td>HEAD</td>
<td>仅仅用于获取对象的基础信息</td>
<td></td>
</tr>
</tbody></table>
<h2 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h2><h3 id="字符串类型"><a href="#字符串类型" class="headerlink" title="字符串类型"></a>字符串类型</h3><h4 id="text-文本类型"><a href="#text-文本类型" class="headerlink" title="text 文本类型"></a>text 文本类型</h4><blockquote>
<p>当一个字段需要用于全文搜索(会被分词), 如：商品名称、商品描述信息，就适合使用<code>text</code>类型</p>
</blockquote>
<ul>
<li><strong>text 的内容会被分词, 可以设置是否需要存储: <code>&quot;index&quot;: &quot;true|false&quot;</code></strong></li>
<li><strong>text 类型的字段不能用于排序, 也很少用于聚合</strong></li>
</ul>
<p><strong>示例</strong></p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">  <span class="attr">"properties"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="attr">"goods_name"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"type"</span>: <span class="string">"text"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"index"</span>: <span class="literal">true</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">  &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">&#125;</span></pre></td></tr></table></figure>

<h4 id="keyword-关键字类型"><a href="#keyword-关键字类型" class="headerlink" title="keyword 关键字类型"></a>keyword 关键字类型</h4><blockquote>
<p>当一个字段需要按照精确值进行过滤、排序、聚合等操作时，就适合使用keyword类型</p>
</blockquote>
<ul>
<li><strong>keyword的内容不会被分词, 可以设置是否需要存储: <code>&quot;index&quot;: &quot;true|false&quot;</code></strong></li>
</ul>
<p><strong>示例</strong></p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">  <span class="attr">"properties"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="attr">"tags"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"type"</span>: <span class="string">"keyword"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"index"</span>: <span class="literal">true</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">  &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">&#125;</span></pre></td></tr></table></figure>

<h3 id="数字类型"><a href="#数字类型" class="headerlink" title="数字类型"></a>数字类型</h3><blockquote>
<p>数字类型分为8种，每种数字类型各有适用的场景；建议尽可能选择范围小的数据类型, 字段的长度越短, 索引和搜索的效率越高；优先考虑使用带缩放因子的浮点类型。</p>
</blockquote>
<table>
<thead>
<tr>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>byte</td>
<td>数字类型①；有符号的8位整数, 范围: [-128 ~ 127]</td>
</tr>
<tr>
<td>short</td>
<td>数字类型②；有符号的16位整数, 范围: [-32768 ~ 32767]</td>
</tr>
<tr>
<td>integer</td>
<td>数字类型③；有符号的32位整数, 范围: [$-2^{31}$ ~ $2^{31}​$-1]</td>
</tr>
<tr>
<td>long</td>
<td>数字类型④；有符号的32位整数, 范围: [$-2^{63}$ ~ $2^{63}​$-1]</td>
</tr>
<tr>
<td>float</td>
<td>数字类型⑤；32位单精度浮点数</td>
</tr>
<tr>
<td>double</td>
<td>数字类型⑥；64位双精度浮点数</td>
</tr>
<tr>
<td>half_float</td>
<td>数字类型⑦；16位半精度IEEE 754浮点类型</td>
</tr>
<tr>
<td>scaled_float</td>
<td>数字类型⑧；缩放类型的的浮点数, 比如price字段只需精确到分, 99.99缩放因子为100, 存储结果为9999</td>
</tr>
<tr>
<td><strong>示例</strong></td>
<td></td>
</tr>
</tbody></table>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">  <span class="attr">"properties"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">// 商品ID</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="attr">"goods_id"</span>: &#123;	</span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"type"</span>: <span class="string">"integer"</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;,</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">// 商品排序</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="attr">"goods_sort"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"type"</span>: <span class="string">"shore"</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;,</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">// 商品价格(通常商品价格会按最小单位存储，也就是精确到分)</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="attr">"goods_price"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"type"</span>: <span class="string">"scaled_float"</span>,	<span class="comment">// 缩放类型的浮点数</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"scaling_factor"</span>: <span class="number">100</span>	<span class="comment">// 比例因子；存储时乘以100</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">  &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">&#125;</span></pre></td></tr></table></figure>

<h3 id="date-日期类型"><a href="#date-日期类型" class="headerlink" title="date  日期类型"></a>date  日期类型</h3><blockquote>
<p>如果时区未指定, 日期将被转换为UTC格式, 但存储的却是长整型的毫秒值.<br>可以自定义日期格式, 若未指定, 则使用默认格式: <code>strict_date_optional_time||epoch_millis</code></p>
</blockquote>
<p><strong>JSON没有日期数据类型，所以在ES中，日期可以是日期字符串或时间戳</strong></p>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line">&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">  <span class="attr">"properties"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">// 创建时间</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="attr">"create_time"</span>: &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"type"</span>: <span class="string">"date"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">      <span class="attr">"format"</span>: <span class="string">"yyyy-MM-dd HH:mm:ss"</span>	<span class="comment">// yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">  &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">&#125;</span></pre></td></tr></table></figure>

<h3 id="boolean-布尔类型"><a href="#boolean-布尔类型" class="headerlink" title="boolean 布尔类型"></a>boolean 布尔类型</h3><blockquote>
<p>接受可以表示真、假的字符串或数字</p>
</blockquote>
<ul>
<li><strong>真值：<code>true</code>, <code>&quot;true&quot;</code>, <code>&quot;on&quot;</code>, <code>&quot;yes&quot;</code>, <code>&quot;1&quot;</code>…</strong></li>
<li><strong>假值：<code>false</code>, <code>&quot;false&quot;</code>, <code>&quot;off&quot;</code>, <code>&quot;no&quot;</code>, <code>&quot;0&quot;</code>, <code>&quot;&quot;</code>(空字符串), <code>0.0</code>,<code>0</code></strong></li>
</ul>
<h3 id="binary-二进制类型"><a href="#binary-二进制类型" class="headerlink" title="binary 二进制类型"></a>binary 二进制类型</h3><blockquote>
<p>二进制类型是Base64编码字符串的二进制值, 不以默认的方式存储, 且不能被搜索. 有2个设置项:</p>
</blockquote>
<ul>
<li><strong><code>doc_values</code>： 该字段是否需要存储到磁盘上，方便以后用来排序、聚合或脚本查询. 接受<code>true</code>和<code>false</code>(默认)</strong></li>
<li><strong><code>store</code>：该字段的值是否要和<code>_source</code>分开存储、检索，意思是除了<code>_source</code>中, 是否要单独再存储一份. 接受<code>true</code>或<code>false</code>(默认)</strong></li>
</ul>
<h3 id="range-范围类型"><a href="#range-范围类型" class="headerlink" title="range 范围类型"></a>range 范围类型</h3><table>
<thead>
<tr>
<th>类型</th>
<th>范围</th>
</tr>
</thead>
<tbody><tr>
<td><code>integer_range</code></td>
<td>$-2^{31}$ ~ $2^{31}-1$</td>
</tr>
<tr>
<td><code>long_range</code></td>
<td>$-2^{63}$ ~ $2^{63}-1$</td>
</tr>
<tr>
<td><code>float_range</code></td>
<td>32位单精度浮点型</td>
</tr>
<tr>
<td><code>double_range</code></td>
<td>64位双精度浮点型</td>
</tr>
<tr>
<td><code>date_range</code></td>
<td>64位整数, 毫秒计时</td>
</tr>
<tr>
<td><code>ip_range</code></td>
<td>IP值的范围, 支持IPV4和IPV6, 或者这两种同时存在</td>
</tr>
</tbody></table>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://jirenyou.gitee.io/blog/2020/01/02/elasticsearch/es-desc/" title="ElasticSearch 入门介绍" target="_blank" rel="external">http://jirenyou.gitee.io/blog/2020/01/02/elasticsearch/es-desc/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://jirenyou.gitee.io/blog" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://jirenyou.gitee.io/blog" target="_blank"><span class="text-dark">Jirry</span><small class="ml-1x">Back end development Architecture</small></a></h3>
        <div>后端开发攻城狮，热爱互联网技术，爱学习，勤思考！</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2020/01/07/java/maven/mvn-pom/" title="Maven pom.xml 配置文件分解"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2020/01/02/elasticsearch/es-rest-api/" title="ElasticSearch RestFul API接口"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/alipay.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/wechat.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2020 Jirry
        
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>